<template>
  <div class="blog-wrapper mb">
    <div class="info">
      <div class="label">{{ blogData.label }}</div>
      <div>
        <span v-if="blogData.type">文章类型：{{ blogData.type }}</span>
        <span v-if="blogData.name">分类：{{ blogData.name }}</span>
      </div>
      <div>
        <span>作者：{{ blogData.user ? blogData.user[0].name : "" }}</span>
        <span>更新于：{{ $t.formatDate(new Date(blogData.updated)) }}</span>
      </div>
    </div>
    <div class="content">
      <!-- <ckeditor v-model="blogData.body" :editor="$ed5" /> -->
      <div v-if="blogData.url">
        <van-image
          width="100%"
          :src="blogData.url | imageUri"
        />
      </div>
      <div class="marked" v-html="$md(blogData.body)" />
    </div>
  </div>
</template>

<script>
import { mapActions } from 'vuex'
export default {
  data() {
    return {
      blogData: {
        body: ''
      }
    }
  },
  created() {
    const params = this.$route.params
    const query = this.$route.query
    if (query.type === 'rz') {
      this.rzDetail({ id: params.id }).then((res) => {
        if (res.data.ok === 1) {
          this.blogData = res.data.data
        }
      })
    } else {
      this.detail({ _id: params.id }).then((res) => {
        if (res.data.ok === 1) {
          this.blogData = res.data.data
        }
      })
    }
  },
  methods: {
    ...mapActions(['detail', 'rzDetail'])
  }
}
</script>

<style lang="scss" scoped>
.blog-wrapper {
  width: 100%;
  .info {
    width: 100%;
    height: 100px;
    padding: 0 8px;
    .label {
      width: 100%;
      height: 40px;
      line-height: 40px;
      font-size: 18px;
      font-weight: 700;
    }
    div {
      width: 100%;
      display: flex;
      justify-content: space-between;
      overflow: hidden;
    }
  }
  .content {
    padding: 0 8px;
  }
}
</style>
